home *** CD-ROM | disk | FTP | other *** search
- Path: isonews.bbn.hp.com!hpbblb!news
- From: Matthias Dittrich <matti>
- Newsgroups: comp.lang.c
- Subject: Re: help with program
- Date: 16 Apr 1996 08:16:14 GMT
- Organization: Hewlett-Packard Co.
- Message-ID: <4kvl0e$g4c@hpbblb.bbn.hp.com>
- References: <4kkgde$t2m@news.duke.edu>
- NNTP-Posting-Host: trabant.bbn.hp.com
- Mime-Version: 1.0
- Content-Type: text/plain; charset=us-ascii
- Content-Transfer-Encoding: 7bit
- X-Mailer: Mozilla 1.1N (X11; I; HP-UX A.09.07 9000/712)
- X-URL: news:4kkgde$t2m@news.duke.edu
-
- kev@acpub.duke.edu (Kevin Daniels) wrote:
- >
- >Can anyone tell me why the following slice of code might be giving the
- >unwanted behavior shown below?
- >
- >
- >void g_find_player1_human_move(void)
- >{
- > int curr_row;
- > int curr_col;
- > int dest_row;
- > int dest_col;
- > int ok = 0;
- > int val;
- > int lcv;
- >
- > while (!ok) {
- >
- > printf("\n\nmove from row -> ");
- > scanf("%d",&curr_row);
- > printf("\n\nmove from col -> ");
- > scanf("%d",&curr_col);
- > printf("\n\nmove to row -> ");
- > scanf("%d",&dest_row);
- > printf("\n\nmove to col -> ");
- > scanf("%d",&dest_col);
- >
- > for(lcv = 1; lcv <=40; lcv ++) {
- > if((RED_ALIVE.p[lcv].row_pos == curr_row) && (RED_ALIVE.p[lcv].col_pos == curr_col) && (RED_ALIVE.p[lcv].placed_on_board == 1)) {
- > ok = g_is_legal_move(RED_ALIVE.p[lcv].row_pos,RED_ALIVE.p[lcv].col_pos,RED_ALIVE.p[lcv].row_pos,RED_ALIVE.p[lcv].col_pos,P1_TURN);
- > if (ok) {
- > g_make_move(RED_ALIVE.p[lcv].row_pos,RED_ALIVE.p[lcv].col_pos,RED_ALIVE.p[lcv].row_pos,RED_ALIVE.p[lcv].col_pos,P1_TURN);
- > }
- > }
- > }
- > }
- >}
- ..
- The function scanf() requires a '\n' character to accept input. You have to
- remove this character from the input stream. A call of fflush(stdin) before
- each scanf() should work.
-
- Good luck,
- Matthais
-
-